Skip to content

Authorization issue #9

@XiangBin520

Description

@XiangBin520

Has the upgraded authorization rule undergone any changes?What additional contracts need to be added for authorization after the upgrade? The previous authorization was carried out in the following manner:

chainID := int64(137)
signerInstance, err := signer.NewPrivateKeySigner(pk, chainID)
if err != nil {
return false, gerror.Wrap(err, "NewPrivateKeySigner")
}

builderCfg := &relay.BuilderConfig{Local: &relay.BuilderCredentials{Key: s.key, Secret: s.secret, Passphrase: s.passphrase}}

client, err := relay.NewRelayClient(consts.RELAYER_HTTP_URL, int64(137), signerInstance, builderCfg, types.RelayerTxSafe)
if err != nil {
return false, gerror.Wrap(err, "NewRelayClient")
}

safeAddress, err := relay.DeriveSafeAddress(chainID, signerInstance.Address().Hex())
if err != nil {
return false, gerror.Wrap(err, "DeriveSafeAddress")
}

deployed, err := client.GetDeployed(ctx, safeAddress)
if err != nil {
return false, gerror.Wrap(err, "GetDeployed")
}
if !deployed {
g.Log().Infof(ctx, "[relayer] Safe owner=%s", signerInstance.Address().Hex())
deployResp, err := client.Deploy(ctx)
if err != nil {
return false, gerror.Wrap(err, "Deploy")
}
receipt, err := deployResp.Wait(ctx)
if err != nil {
return false, gerror.Wrap(err, "Deploy Wait")
}
g.Log().Infof(ctx, "[relayer] Safe proxy=%s tx=%s", receipt.ProxyAddress, receipt.TransactionHash)
} else {
g.Log().Infof(ctx, "[relayer] Safe address=%s", safeAddress)
}

usdc := consts.USDC_CONTRACT_ADDRESS
if v, e := g.Cfg("config").Get(ctx, "relayer.usdcAddress"); e == nil && v.String() != "" {
usdc = strings.TrimSpace(v.String())
}
spender := consts.EXCHANGE_CTF_ADDRESS
if v, e := g.Cfg("config").Get(ctx, "relayer.usdcApproveSpender"); e == nil && v.String() != "" {
spender = strings.TrimSpace(v.String())
}

data, err := encode.EncodeErc20Approve(common.HexToAddress(spender), libconst.MaxUint256)
if err != nil {
return false, gerror.Wrap(err, "EncodeErc20Approve")
}
tx := types.Transaction{
To: usdc,
Data: "0x" + common.Bytes2Hex(data),
Value: "0",
}

execResp, err := client.Execute(ctx, []types.Transaction{tx}, "polymarket-trading-bot: usdc-approve-ctf")
if err != nil {
return false, gerror.Wrap(err, "Execute")
}
execReceipt, err := execResp.Wait(ctx)
if err != nil {
return false, gerror.Wrap(err, "Execute Wait")
}
g.Log().Infof(ctx, "[relayer] USDC approve tx=%s", execReceipt.TransactionHash)
return true, nil

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions